package com.project.service.impl;

import lovo.roomProject.project.bean.FacilityBean;
import lovo.roomProject.project.mapper.IFacilityMapper;
import lovo.roomProject.project.service.IFacilityService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class FacilityServiceImpl extends BaseService implements IFacilityService {

    @Override
    public void addFacility(FacilityBean facility) {
        SqlSession session = this.getSession();
        IFacilityMapper mapper = session.getMapper(IFacilityMapper.class);
        mapper.addFacility(facility);
        session.commit();
        session.close();
    }

    @Override
    public void updateFacility(int FacilityId, String status, int roomId) {
        SqlSession session = this.getSession();
        IFacilityMapper mapper = session.getMapper(IFacilityMapper.class);
        mapper.updateFacility(FacilityId, status);
        session.commit();
        session.close();
    }

    @Override
    public List<FacilityBean> findById(int roomId) {
        SqlSession session = this.getSession();
        IFacilityMapper mapper = session.getMapper(IFacilityMapper.class);
        List<FacilityBean> list = mapper.findById(roomId);
        session.close();
        return list;
    }

    public static void main(String[] args) {
        IFacilityService fs = new FacilityServiceImpl();
//        fs.addFacility(new FacilityBean("炸了", 3));
//        System.out.println(fs.findById(2));
//        fs.updateFacility(3, 2);
//        fs.updateFacility(4, 2);
//        fs.updateFacility(8, 1);0.
//        fs.addFacility(new FacilityBean("没了", 1));
//        fs.updateFacility(7, "已解决", 1);
    }
}
